// 页面路由
const express = require('express');
const router = express.Router();
// 引入path模块
const path = require('path');
// 处理上传图片的模块
const multer  = require('multer');
// 定义上传图片的文件夹
const upload = multer({ dest: path.join(__dirname,'../public/img/') });

// 引入页面中间件
const { index, boutique, free, detail, search, user, article } = require('../middleware/page');
// 引入用户设置逻辑中间件
const { register, login, quit, uploads } = require('../middleware/user');
// 引入发布文章逻辑中间件
const { publish, downs } = require('../middleware/article');

// GET index page.   route.get/post(fn)   路由级中间件
router.get('/',index);
// GET boutique page.
router.get('/boutique',boutique);
// GET free page. 
router.get('/free',free);
// GET detail page. 
router.get('/detail',detail);
// GET search page. 
router.get('/search',search);
// GET user page. 
router.get('/user',user);
// GET article page. 
router.get('/article',article);

// 注册路由   /api/register
router.post('/register',register);
// 登录路由   /api/login
router.post('/login',login);
// 清除登录用户信息路由
router.post('/quit',quit);
// 用户设置-文件上传路由 upload.single('avatar') avatar对应的是前端 input类型为file的name值
router.post('/upload',upload.single('avatar'),uploads);
// 发布文章-文件上传路由 upload.single('avatar') avatar对应的是前端 input类型为file的name值
router.post('/publish',upload.single('thumb'),publish);
// 用户点赞
router.post('/downs',downs);

// 暴露路由
module.exports = router;
